//
//  LGFriendDetailViewController.m
//  ligenyun
//
//  Created by Mac on 2018/4/10.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGFriendDetailViewController.h"
#import "LGDaoWenTableViewCell.h"
#import "LGFriendLingyuanViewController.h"
#import "LGFriendCitangViewController.h"
#import "LGFriendXunGenViewController.h"
#import "LGFriendDaoWenViewController.h"
@interface LGFriendDetailViewController ()

@end

@implementation LGFriendDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"亲友详情";
    [self configSubView];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 30)];
    header.backgroundColor = self.tableView.backgroundColor;
    
    STButton * iconButton = [[STButton alloc] initWithFrame:CGRectMake(15, 10, 60, 60)
                                                      title:nil
                                                 titleColor:nil
                                                  titleFont:0
                                               cornerRadius:30
                                            backgroundColor:nil
                                            backgroundImage:[UIImage imageNamed:@"1"]
                                                      image:nil];
    iconButton.centerX = UIScreenWidth / 2;
    [header addSubview:iconButton];
    
    STLabel * nameLable = [[STLabel alloc] initWithFrame:CGRectMake(iconButton.right + 10, iconButton.bottom + 10, UIScreenWidth, 20)
                                                    text:@"名字"
                                               textColor:FirstTextColor
                                                    font:16
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentCenter];
    [header addSubview:nameLable];
    nameLable.centerX = UIScreenWidth / 2;
    
    STButton * qiandaoButton = [[STButton alloc] initWithFrame:CGRectMake(0, nameLable.bottom  +20, 100, 25)
                                                         title:@"添加亲友"
                                                    titleColor:FlatWhite
                                                     titleFont:14
                                                  cornerRadius:4
                                               backgroundColor:TM_redColor
                                               backgroundImage:nil
                                                         image:nil];
    qiandaoButton.centerX = UIScreenWidth / 2;
    qiandaoButton.userInteractionEnabled = YES;
    [qiandaoButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedAddFriend];
    }];
    qiandaoButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [header addSubview:qiandaoButton];
    
    CGFloat itemWith = (UIScreenWidth-30) / 3;
    STLabel * moneyLable = [[STLabel alloc] initWithFrame:CGRectMake(15, qiandaoButton.bottom + 20, itemWith, 30)
                                                     text:@"礼根币:3000币"
                                                textColor:SecendTextColor
                                                     font:13
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [header addSubview:moneyLable];
    
    STLabel * pointLable = [[STLabel alloc] initWithFrame:CGRectMake(moneyLable.right, qiandaoButton.bottom + 20, itemWith, 30)
                                                     text:@"积分:3000"
                                                textColor:SecendTextColor
                                                     font:13
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [header addSubview:pointLable];
    
    STButton * addButton = [[STButton alloc] initWithFrame:CGRectMake(pointLable.right, qiandaoButton.bottom + 20, itemWith, 30)
                                                     title:@"北京市朝阳区"
                                                titleColor:SecendTextColor
                                                 titleFont:13
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"陵墓坐标"]];
    addButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [header addSubview:addButton];
#pragma mark --item
    NSArray * array = @[@{@"title":@"ta的陵园",@"imageName":@"亲友03"},
                        @{@"title":@"ta的祠堂",@"imageName":@"亲友04"},
                        @{@"title":@"ta的寻根",@"imageName":@"亲友05"},
                        @{@"title":@"ta的悼文",@"imageName":@"亲友06"},
                        @{@"title":@"ta的亲友",@"imageName":@"亲友07"},
                        @{@"title":@"关注的陵园",@"imageName":@"亲友08"},
                        @{@"title":@"祭祀记录",@"imageName":@"亲友09"}
                        ];
    CGFloat controlWith = UIScreenWidth / 4;
    CGFloat top = 0;
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, addButton.bottom + 30, UIScreenWidth, controlWith * 2)];
    imageView.backgroundColor = [UIColor whiteColor];
    imageView.userInteractionEnabled = YES;
    [header addSubview:imageView];
    for (NSInteger i = 0 ; i < array.count;i ++) {
        NSDictionary * dic = array[i];
        NSString * imageName = dic[@"imageName"];
        NSString * title = dic[@"title"];
        STMenuControl * menuControl = [[STMenuControl alloc] initWithFrame:CGRectMake(0, 0, controlWith, controlWith) imageName:imageName title:title titleColor:FirstTextColor];
        [menuControl setOnSelctedControl:^(STMenuControl *control) {
            [weakSelf onSetctedMenuButtonWithTitle:title];
        }];
        menuControl.tag = 10000 + i;
        [imageView addSubview:menuControl];
        
        menuControl.left = (i%4) * controlWith;
        menuControl.top = (i/4) * controlWith + top;
        //top = menu.bottom;
        
    }

    UIView * sectionHeader = [TMUtils headerViewWithTitle:@"推荐观看"];
    sectionHeader.top = imageView.bottom;
    header.height = sectionHeader.bottom;
    [header addSubview:sectionHeader];
    self.tableView.tableHeaderView = header;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 10;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [LGDaoWenTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 5;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    LGDaoWenTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[LGDaoWenTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma mark --Action Method
- (void)onSelectedAddFriend{
    
}
- (void)onSetctedMenuButtonWithTitle:(NSString*)title{
    if ([title isEqualToString:@"ta的陵园"]) {
        [self.navigationController pushViewController:[LGFriendLingyuanViewController new] animated:YES];
    }
    if ([title isEqualToString:@"ta的祠堂"]) {
        [self.navigationController pushViewController:[LGFriendCitangViewController new] animated:YES];
    }
    if ([title isEqualToString:@"ta的寻根"]) {
        [self.navigationController pushViewController:[LGFriendXunGenViewController new] animated:YES];
    }
    if ([title isEqualToString:@"ta的悼文"]) {
        [self.navigationController pushViewController:[LGFriendDaoWenViewController new] animated:YES];
    }
    
}
@end
